package com.gzmu.storage.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gzmu.storage.entity.Cabinet;
import com.gzmu.storage.service.AdminlogService;
import com.gzmu.storage.service.CabinetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-04-16
 */
@Controller
@RequestMapping("/cabinet")
public class CabinetController {
    @Autowired
    private CabinetService cabinetService;
    @Autowired
    private AdminlogService adminlogService;

    @ResponseBody
    @RequestMapping("addCabinet")
    public Object addCabinet(Cabinet cabinet){
        Map map = new HashMap<>();
        Date date = new Date(  );
        cabinet.setCreatetime( date );
        cabinet.setUpdatetime( date );
        cabinet.setRemark( "档案柜" );
//        cabinet.setStatus( 0 );
        boolean b = cabinetService.insertAndUpdate( cabinet );
        adminlogService.insertAdminlog("添加" + cabinet.getName() + "档案柜");
        map.put( "code", b);
        return JSONObject.toJSON(map);
    }

    @ResponseBody
    @RequestMapping("getCabinet")
    public Object getCabinet(String id){
        Map map = new HashMap<>();
        EntityWrapper wrapper = new EntityWrapper(  );
        wrapper.eq( "stationid", id);
        List<Cabinet> cabinets = cabinetService.selectList( wrapper );
        map.put( "code", true);
        map.put( "data", cabinets );
        return JSONObject.toJSON(map);
    }
}

